package com.atguigu.spzx.manager.service.impl;

import cn.hutool.core.date.DateTime;
import com.atguigu.spzx.manager.mapper.OrderStatisticsMapper;
import com.atguigu.spzx.manager.service.OrderStatisticsService;
import com.atguigu.spzx.model.entity.order.OrderStatistics;
import com.atguigu.spzx.model.vo.order.OrderStatisticsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * title:
 * author: zgl
 * date: 2024/1/8
 * description：
 */
@Service
public class OrderStatisticsServiceImpl implements OrderStatisticsService {
    @Autowired
    private OrderStatisticsMapper orderStatisticsMapper;
    @Override
    public OrderStatisticsVo getStatisticsList(String begin, String end) {
        List<OrderStatistics> orderStatisticsList = orderStatisticsMapper.getStatisticsList(begin,end);
        List<String> dateList = orderStatisticsList.stream().map(orderStatistics -> new DateTime(orderStatistics.getOrderDate()).toString("yyyy-MM-dd")).collect(Collectors.toList());
        List<BigDecimal> amountList = orderStatisticsList.stream().map(OrderStatistics::getTotalAmount).collect(Collectors.toList());
        List<Integer> totalNum = orderStatisticsList.stream().map(OrderStatistics::getTotalNum).collect(Collectors.toList());
        OrderStatisticsVo orderStatisticsVo = new OrderStatisticsVo();
        orderStatisticsVo.setDateList(dateList);
        orderStatisticsVo.setTotalNum(totalNum);
        orderStatisticsVo.setAmountList(amountList);
        return orderStatisticsVo;
    }
}
